//
//  ZTListTableViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "ZTListTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>


#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@implementation ZTListTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
    }
    
    return self;
}

-(void)createCell
{

    self.newsPic = [UIImageView new];
    self.newsPic.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.newsPic];

    [self.newsPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(15);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.width.offset(80);
        
    }];

    
    self.newsTitle = [UILabel new];
    self.newsTitle.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.newsTitle];
    
    [self.newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.contentView).offset(15);
        make.width.offset(200);
        make.height.offset(20);
        
    }];

    self.newsDigest = [UILabel new];
    self.newsDigest.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.newsDigest];
    self.newsDigest.font = [UIFont systemFontOfSize:13 weight:0];
    self.newsDigest.textColor = [UIColor lightGrayColor];
    self.newsDigest.numberOfLines = 2;

    [self.newsDigest mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsTitle.mas_bottom).offset(20);
        make.width.offset(200);
        make.height.offset(20);
        
    }];

    self.contentCount = [UILabel new];
    self.contentCount.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.contentCount];
    self.contentCount.font = [UIFont systemFontOfSize:13 weight:0];
    self.contentCount.textAlignment = NSTextAlignmentRight;
    self.contentCount.textColor = [UIColor lightGrayColor];
    
    [self.contentCount mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsDigest.mas_bottom).offset(20);
        make.width.offset(70);
        make.height.offset(20);
        
    }];
    

    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextBtn.backgroundColor = [UIColor clearColor];
    [self.nextBtn setImage:[UIImage imageNamed:@"findcell_arrow@2x.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.nextBtn];
    
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-20);
        make.bottom.equalTo(self.contentView).offset(-40);
        make.width.offset(30);
        make.height.offset(30);
        
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(100);
        make.top.equalTo(self.newsPic.mas_top).offset(-10);
        make.width.offset(WIDTH - 100);
        make.height.offset(0.5);

        
    }];
    
    
    
}

- (void)setListModel:(ZTListModel *)listModel
{
    _listModel = listModel;

    NSURL *url = [NSURL URLWithString:listModel.coverPath];
    [self.newsPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    self.newsTitle.text = listModel.title;
    self.newsDigest.text = [NSString stringWithFormat:@"1 %@", listModel.firstTitle];
    self.contentCount.text = listModel.subtitle;
}

- (void)setModel:(ZHListModel *)model{
    _model = model;
    NSLog(@"smallLogo = %@",model.middleLogo);
    NSURL *url = [NSURL URLWithString:model.middleLogo];
    [self.newsPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    self.newsTitle.text = model.personDescribe;
    self.contentCount.text = model.nickname;

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
